"use server";
import { prisma } from "@/lib/db";
import { handlerAction } from "@/lib/handlerAction";
import { Menu } from "@prisma/client";

export const menuList = handlerAction<Menu[]>(async () => {
  return await prisma.menu.findMany({
    orderBy: {
      sort: "asc",
    },
  });
});
export const menuAdd = handlerAction<Menu, Menu>(async (params: Menu) => {
  return prisma.menu.create({
    data: params,
  });
});
export const menuDelete = handlerAction<Menu>(async (params: Menu) => {
  return prisma.menu.delete({
    where: {
      id: params.id,
    },
  });
});
export const menuUpdate = handlerAction<Menu>(async (params: Menu) => {
  return prisma.menu.update({
    where: {
      id: params.id,
    },
    data: params,
  });
});
